package com.rom.ratethehell.rate.custom_views;

import com.rom.ratethehell.R;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class WriteCommentView extends RelativeLayout {
	private OnEnterListener listener;

	public WriteCommentView(Context context) {
		super(context);
		init(context);
	}

	public WriteCommentView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public WriteCommentView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	private TextView userNameView;
	private EditText writeDataView;

	private void init(Context context) {
		LayoutInflater inflater = (LayoutInflater) getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.view_write_comment, this);
		userNameView = (TextView) findViewById(R.id.comment_user_name);
		writeDataView = (EditText) findViewById(R.id.comment_data);
		writeDataView.setOnEditorActionListener(new OnEditorActionListener() {

			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {

				if (event != null && event.getAction() == KeyEvent.ACTION_DOWN) {
					if (!event.isShiftPressed()) {
						listener.onEnter(v.getText().toString());
						writeDataView.setText("");
					}
				}
				return false;
			}
		});
	}

	public void setOnEnterListener(OnEnterListener l) {
		listener = l;
	}



}
